<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原型 继承</title>
</head>
<body>


<script>

    function person(name, age) {
        this.name = name;
        this.age = age;
        this.type = 'person';
    }

    person.prototype.sayhello = function () {
        alert(this.name);
    }

    var p1 = new person('李二狗', '21');
    p1.type = 'dog';
    var p2 = new person('李三狗', '20');

    console.log(p1);
    console.log(p2);

    function student() {
    }

    student.prototype = new person('王铁牛', '19');
    var s1 = new student();
    student.prototype.grade = 5;
    student.prototype.inrt = function () {
        alert(this.grade);
    }

    person.prototype.sayhello = function () {
        alert('newSayhello:' + this.name);
    }

    //s1.sayhello();  //newSayhello:王铁牛
    //s1.inrt();   //5


    var a, b;
    (function () {

        function A(arg1, arg2) {
            this.a = 1;
            this.b = 2;
        }

        A.prototype.log = function () {
            console.log(this.a);
        }

        a = new A();
        b = new A();
    })()


    a.log();
    b.log();

    a.constructor.prototype.log2 = function () {
        console.log(this.b);
    }
    a.__proto__.log3 = function () {
        console.log(this.a + '-' + 3);
    }
    a.log2();
    a.log3();
    //得到参数名
    a.constructor
        .toString()
        .match(/\(.*\)/)
        .pop().slice(1, -1)
        .split(',');


    console.log(A);//Uncaught ReferenceError: A is not defined
</script>
</body>
</html>